package com.himaci.framework.utility;

import java.util.Random;

/**
 * Kelas utility untuk membantu perhitungan matematis
 *
 * @author XNPSDN
 */
public final class NumberUtils {

    private static NumberUtils instance;
    private Random randomGenerator;

    /**
     * Private konstruktor
     */
    private NumberUtils() {
	randomGenerator = new Random();
    }

    /**
     * Mendapatkan singleton instance
     * @return Instance dari kelas NumberUtils
     */
    public static synchronized NumberUtils getInstance() {
	if (instance == null) {
	    instance = new NumberUtils();
	}
	return instance;
    }

    /**
     * Mendapatkan nilai integer random
     * @param size Rentang nilai
     * @return Hasil random
     */
    public int generateRandomInt(int size) {
	return randomGenerator.nextInt(size);
    }

    /**
     * Mendapatkan nilai float random
     * @param size Rentang nilai
     * @return Hasil random
     */
    public float generateRandomFloat(float size) {
	return randomGenerator.nextFloat() * size;
    }
}
